package ui;

import rn.AccessAPI;
import rn.DniException;
import rn.EdadFormatoException;
import rn.NombreFormatoException;

public class TextoUI {

	public static void main(String[] args){
		AccessAPI c=new AccessAPI();
		switch (args[0]){
			case "c":
				try {
					c.insertar(Integer.parseInt(args[1]), args[2], Integer.parseInt(args[3]));
				} catch (DniException e) {
					System.out.println(e.getMessage());
				} catch (NombreFormatoException e){
					System.out.println(e.getMessage());
				} catch (EdadFormatoException e){
					System.out.println(e.getMessage());
				}
				break;
			case "r":
				try {
					System.out.println("El nombre del dni 30 es "+c.getNombre(Integer.parseInt(args[1]))+" y la edad "+c.getEdad(Integer.parseInt(args[1])));
				} catch (DniException e) {
					System.out.println(e.getMessage());
				}
				break;
			case "u":
				if(args[2].equals("edad")){
					try{
						c.modificar(Integer.parseInt(args[1]), Integer.parseInt(args[3]));
					}catch(DniException e){
						System.out.println(e.getMessage());
					}catch(EdadFormatoException e){
						System.out.println(e.getMessage());
					}
				}else if(args[2].equals("nom")){
					try{
						c.modificar(Integer.parseInt(args[1]), args[3]);
					}catch(DniException e){
						System.out.println(e.getMessage());
					}catch(NombreFormatoException e){
						System.out.println(e.getMessage());
					}
				}
				break;
			case "d":
				try{
					c.borrar(Integer.parseInt(args[1]));
				}catch(DniException e){
					System.out.println(e.getMessage());
				}
				break;
			default:
				System.out.println("No se han introducido correctamente los argumentos de entrada");
		}
	}
	
}
